package com.qen.yanggao

import cn.hutool.db.Db
import cn.hutool.poi.excel.ExcelUtil

fun main() {
    val list = Db.use()
        .query("SELECT b.dname,a.dcvalue,a.dcode FROM usercenter.dictionarycontent a,usercenter.dictionarys b WHERE a.did = b.did ")
    val rows = ArrayList<DictData>()

    for (entity in list) {
        rows.add(
            DictData(
                code = "utf8",
                type = entity.getStr("dname"),
                value = entity.getStr("dcode"),
                remark = entity.getStr("dcvalue"),
            )
        )
    }
    outExcel(rows)
}

data class DictData(
    val code: String = "utf8mb4",
    val type: String = "",
    val value: String = "",
    val remark: String = "",
)

fun outExcel(rows: ArrayList<DictData>) {
    val writer = ExcelUtil.getWriter("${OutPath}6数据表登记导入模板Sheet1.xlsx")
    writer.addHeaderAlias("code", "数据库名称")
    writer.addHeaderAlias("type", "数据库编码")
    writer.addHeaderAlias("value", "数据库编码")
    writer.addHeaderAlias("remark", "数据库编码")
    writer.write(rows, true)
    writer.close()
}